<?php
//if (isset($_SESSION['username'])) {
include_once 'header.php';
require_once("conn.php");
require_once("change_page.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>乐知家园</title>
        <script language="javascript">
            function deleteproduct(id,name,page){
                var str = "\u786e定删除 " + name + "\uff1f";
                if(confirm(str)){
                    location.href = "deleteSearch.php?ids=" + id + "&page=" + page;
                }
            }
            function approve(id,direct,name,page){
                var str = "";
                if(direct=="up"){
                    str = name + " \u786e定发布？";
                }else if(direct=="down"){
                    str = name + " \u786e定下线？";
                }
                if(confirm(str)){
                    location.href = "approveSearch.php?ids=" + id + "&direct=" + direct + "&page=" + page;
                }
            }
            function change_age(){
                var page = document.getElementById("current_page").value;
                location.href = "searchList.php?page=" + page+"&menu=search";
            }
            function click_all(e){
                var checkboxes = document.getElementsByName("product_checkbox");
                for(var i=0;i<checkboxes.length;i++){
                    if(e.checked){
                        checkboxes[i].checked = true;
                    }else{
                        checkboxes[i].checked = false;
                    }
                }
            }
            function delete_product_multi(){
                var str = "\u786e定删除选中的应用？";
                if(confirm(str)){
                    var ids = "";
                    var checkboxes = document.getElementsByName("product_checkbox");
                    for(var i=0;i<checkboxes.length;i++){
                        if(checkboxes[i].checked){
                            ids = ids + checkboxes[i].value + ",";
                        }
                    }
                    location.href = "deleteSearch.php?ids=" + ids;
                }
            }
        </script>
        <style type="text/css">
            <!--
            body,td,th {
                font-family: 微软雅黑;
                font-size: 14px;
                color: #000000;
            }

            .STYLE1 {color: #FFFFFF}
            -->
        </style></head>
    <body>
        <br/>
        <table width="80%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
            <tr align="align">                
                <td bgcolor="#FFFFFF" align="right"><?php
                $db = new DBC();                
                ?></td>
            </tr>
        </table>
        <br/>
        <table width="80%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#9999FF">
            <tr align="center">
                <td bgcolor="#666666"><span class="STYLE1">位置</span></td>                
                <td bgcolor="#666666"><span class="STYLE1">时间</span></td>
                <td bgcolor="#666666"><span class="STYLE1">状态</span></td>
                <td bgcolor="#666666"><span class="STYLE1">发布</span></td>
                <td bgcolor="#666666"><span class="STYLE1">操作</span></td>
                <td bgcolor="#666666"><span class="STYLE1">点击数</span></td>
            </tr>
            <?php
            if (isset($_GET['keyword'])) {
                $keyword = trim($_GET['keyword']);
//                $sql = "SELECT * FROM t_search_info WHERE (flashcode LIKE '%" . $keyword . "%' OR name LIKE '%" . $keyword . "%') " . $age_sql_and . " ORDER BY flashcode LIMIT " . $begin . "," . $page_size;
            } else {
                $sql = "SELECT * FROM t_search_info ORDER BY id LIMIT 9";
            }
            $data = $db->fetchData($sql);
            if ($data != false && count($data)) {
                for ($i=0;$i<count($data);$i++) {
                    $product = $data[$i];
                    if ($product['status'] == "0") {
                        $status = "<font color='brown'>未发布</font>";
                    } else if ($product['status'] == "1") {
                        $status = "<font color='green'>已发布</font>";
                    } else if ($product['status'] == "-1") {
                        $status = "<font color='red'>已下线</font>";
                    }                    
                    ?>
                    <tr>
                        <td bgcolor="#FFFFFF" align="center"><?php echo $product['position']; ?></td>
                        <td bgcolor="#FFFFFF">&nbsp;<?php echo $product['updateTime']; ?></td>
                        <td bgcolor="#FFFFFF">&nbsp;<?php echo $status; ?></td>
                        <td align="center" bgcolor="#FFFFFF"><?php if ($product['status'] == "0" || $product['status'] == "-1") { ?>&nbsp;<a href="#" onclick="approve('<?php echo $product['id']; ?>','up','<?php echo $product['position']; ?>','0')">发布</a><?php } else if ($product['status'] == "1") { ?>&nbsp;<a href="#" onclick="approve('<?php echo $product['id']; ?>','down','<?php echo $product['position']; ?>','0')">下线</a><?php } ?></td>
                        <td align="center" bgcolor="#FFFFFF"><a href="searchEdit.php?menu=search&id=<?php echo $product['id']; ?>">编辑</a>&nbsp;</td>
                        <td align="center" bgcolor="#FFFFFF"><?php echo $product['click']; ?></td>
                    </tr>
                    <?php
                }
            }
            ?>
        </table>
    </body>
</html>
<?php
include_once 'footer.php';
//} else {
//    header("login.php");
//}
?>